<!DOCTYPE html>
<html>
<head>
    <title>设备功能测试</title>
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no"
          charset="UTF-8"/>
    <meta http-equiv="Cache-control" content="Cache-Control: max-age=3600, must-revalidate">

<!--    <meta http-equiv="Cache-control" content="Cache-Control: max-age=3600,no-cache">-->
    <style type="text/css">
        * {
            margin: 0;
            padding: 0;
        }
        .box {
            text-align: center;
        }
        .btn {
            line-height: 24px;
            text-align: center;
            font-size: 14px;
            border: 1px solid blue;
            background-color: #fff;
            margin-bottom: 20px;
            padding: 0 10px;
        }
        .message {
            position: fixed;
            bottom: 0;
            width: 100%;
            padding: 10px;
            font-size: 14px;
            color: #000;
            height: auto;
            word-wrap:break-word;
            word-break:break-all;
            overflow: hidden;
        }
    </style>
    <script src="../js/autoQR.js"></script>
    <script src="../js/jquery.min.js"></script>
<!--    <script src="../js/JXBJSBridge2.js"></script>-->
    <script src="../js/HKNativeJSBridge.js?=v0.2"></script>
<!--    <script src="../js/LBXCustomBase64.js"></script>-->
<!--    <script src="../js/vconsole.min.js"></script>-->

<!--    <script src="https://cdn.bootcdn.net/ajax/libs/react/17.0.1/cjs/react-jsx-dev-runtime.development.js"></script>-->


    <script>
    // 初始化
    // var vConsole = new VConsole();
    // console.log('init vConsole');
    </script>
</head>
<body>
<div class="box">
    <div class="message" id="message"></div>
    <br/>
    <button class="btn" onclick="testCamera()">相机</button>
    <button class="btn" onclick="testAlbum()">相册</button>
    <br/>
    <button class="btn" onclick="testDial()">拨打电话</button>
    <button class="btn" onclick="testGetDeviceInfo()">设备信息</button>
    <button class="btn" onclick="testLocation()">位置坐标</button>
    <button class="btn" onclick="testLocation1()">位置信息</button>

    <br/>
    <button class="btn" onclick="tesGethttp()">http-get接口</button>
    <button class="btn" onclick="tesPosthttp()">http-post接口</button>
    <br/>
    <button class="btn" onclick="ocrIDfront()">OCR身份证正面</button>
    <button class="btn" onclick="ocrIDback()">OCR身份证反面</button>
    <button class="btn" onclick="ocrBackID()">OCR银行卡</button>
    <br/>
    <button class="btn" onclick="ocrJiashizheng()">OCR驾驶证</button>
    <button class="btn" onclick="ocrChejiahao()">OCR车架号</button>
<!--    <button class="btn" onclick="ocrXingshizheng()">OCR行驶证</button>-->
    <br/>

    <button class="btn" onclick="testBAudio()">短语音识别</button>

    <button class="btn" onclick="testClassify()">资源分类</button>

    <button class="btn" onclick="testQRCodeScan()">二维码扫描10</button>
    <br/>
    <img id="imgID" style="width: 200px;height: 200px" src="">

    <!--    <img style='width:200px;height:200px;' src='data:image/png;base64,"+basedata+"'>;-->


    <!--    <img src="-->
</div>

<script>

/*
使用let 在ios10以下版本会报错
* */

    function testCamera() {

        hkNativeDevice.camera({edit: true, wantFilePath: true,wantBase64Data:true},photoResult);
        // if (window.hkNativeAndroid)
        // {
        //     window.hkNativeAndroid.postMessage(
        //             "Device",
        //             "camera",
        //             JSON.stringify({edit: true, wantFilePath: true,wantBase64Data:true}),
        //             123
        //     );
        // }
        // else if(hkNativeAndroid)
        // {
        //     console.log("exist hkNativeAndroid");
        // }
        // else
        // {
        //     console.log('not exist hkNativeAndroid');
        // }
    }

    function testClassify() {

        hkNativeMedia.classify({caseNO:'testCaseNO123',userCode:'15852509988',loanApplyNo:'lan',policyNo:'pn'},null);
    }

    function photoResult(obj) {

        if (obj.status == 1){
            if (obj.base64) {
                var src = "data:image/" + obj.type + ";base64," + obj.base64;

                var img = document.getElementById('imgID');

                img.src = src;
                document.getElementById('message').innerHTML = 'base64';
                console.log('base64 image');

            } else if (obj.filePath) {
                var img = document.getElementById('imgID');

                //图片路径需要和当前html在同一个目录下
                img.src = obj.filePath;

                document.getElementById('message').innerHTML = obj.filePath;

            }
            else {
                document.getElementById('message').innerHTML = "status:" + obj.status;
            }
        }
        else {
            document.getElementById('message').innerHTML = obj.des;
        }
    }

    function testAlbum() {

        hkNativeDevice.album({edit: true, wantFilePath: true,wantBase64Data:true},photoResult);

    }

    function testDial() {

        hkNativeDevice.dial({phoneNum:"10086"},null);
    }

    function bdOCR(type) {

        hkNativeBocr.rec({type:type,wantBase64:false},function (obj) {

            console.log(obj);
            var str = JSON.stringify(message);
            console.log(str);
            if (obj.base64){
                var src = "data:image/" + obj.type + ";base64," + obj.base64;

                var img = document.getElementById('imgID');

                img.src = src;
            }
            document.getElementById('message').innerHTML = obj.status ? obj.data : obj.des;
        })
    }

    function ocrIDfront() {

        bdOCR(1);
    }
    function ocrIDback() {

        bdOCR(2);
    }
    function ocrBackID() {

        bdOCR(3);
    }
    function ocrJiashizheng() {

        bdOCR(7);
    }
    function ocrChejiahao() {

        bdOCR(8);
    }
    function ocrXingshizheng() {

        bdOCR(9);
    }

    function testOCR() {

        hkNativeBocr.rec({type:1,wantBase64:false},function (obj) {

            console.log(obj);
            var str = JSON.stringify(message);
            console.log(str);
            if (obj.base64){
                var src = "data:image/" + obj.type + ";base64," + obj.base64;

                var img = document.getElementById('imgID');

                img.src = src;
            }
            document.getElementById('message').innerHTML = obj.status ? obj.data : obj.des;
        })
    }

    function testBAudio() {

        hkNativeBaudio.rec({type:1},function (obj) {

            if (obj.status) {

                document.getElementById('message').innerHTML = obj.data;
            }
        })
    }

    function testGetDeviceInfo() {

        // 参数名称	描述	参数类型
        // deviceID	是否需要硬件号	bool
        // netType	是否需要当前网络类型	bool
        // deviceType	是否需要设备类型	bool
        hkNativeDevice.deviceInfo({deviceID:true,netType:true,deviceType:true,sysVer:true},function (jsonObj) {

            if (jsonObj.status)
            {
                document.getElementById('message').innerHTML = jsonObj.deviceID + ' ' + jsonObj.deviceType + ' ' + jsonObj.netType + ' ' + jsonObj.sysVer;
            }
            else {
                document.getElementById('message').innerHTML = jsonObj.des;
            }
        })
    }

    function testLocation() {

        hkNativeDevice.location({wantAddress: false,type:0,wantContinuous:false},function (message) {

            var str = JSON.stringify(message);

            document.getElementById('message').innerHTML = "locaiton:" + str;
        });
    }
function testLocation1() {

    hkNativeDevice.location({wantAddress: true,type:0,wantContinuous:false},function (message) {

        var str = JSON.stringify(message);

        document.getElementById('message').innerHTML = "locaiton:" + str;
    });
}

    function tesGethttp() {

        // hkNativeHttp.get({
        //     url: "http://" + window.location.host + "/request",
        //     headers: {"Content-Type":"application/json"},
        //     params: {id: "2", pwd: "val2"}
        // },function (message) {
        //
        //     var str = JSON.stringify(message); //返回字符串
        //
        //     document.getElementById('message').innerHTML = "http get response:" + str;
        // })

        this.testAjaxPost();

    }

    function testAjaxGet() {

        // LBXHookAjax();

        var url = 'https://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=15852509988';
        //跨域服务器也需要配置支持才可以
        // url = "http://192.168.0.110:8080/request?id=1&pwd=val1";
        // url = "http://192.168.0.106:8080/request";

        $.ajax(url, {

            //jsonp 服务器返回json格式数据,不设置也是json对象，如果设置了，oc编写的json， 提示parse fail
            dataType: 'jsonp',
            crossDomain: true,//跨域
            jsonp: 'callback',
            type: 'get',//HTTP请求类型
            timeout: 10000,//超时时间设置为10秒；
            async: true,
            success: function (data) {
                if (data) {
                    var str = JSON.stringify(data);
                    document.getElementById('message').innerHTML = "http get response:" + str;
                    // console.log(str);
                }
            },
            error: function (xhr, type, errorThrown) {
                console.log("ajax  error:" + type);

                document.getElementById('message').innerHTML =  "ajax get error:" + type;
                //alert(xhr);
            }
        });
    }

    function testAjaxPost() {

        var url = 'https://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=15852509988';
        //跨域服务器也需要配置支持才可以
        url = "http://192.168.0.110:8080/request";


        $.ajax(url, {
            data: {
                "id":"1",
                "pwd":"val1"
            },
            //jsonp 服务器返回json格式数据,不设置也是json对象，如果设置了，oc编写的json， 提示parse fail
            dataType: 'jsonp',
            crossDomain: true,//跨域
            jsonp: 'callback',
            type: 'POST',//HTTP请求类型
            timeout: 10000,//超时时间设置为10秒；
            async:true,
            cache:false,
            contentType: "application/json",
            success: function (data) {
                if (data) {
                    var str = JSON.stringify(data);
                    document.getElementById('message').innerHTML = "http post response:" + str;
                }
            },
            error: function (xhr, type, errorThrown) {
                console.log("ajax  error:" + type);

                document.getElementById('message').innerHTML =  "ajax post on error:" + type;
                //alert(xhr);
            }
        });
    }

    function tesPosthttp() {

        hkNativeHttp.post({
            url: "http://" + window.location.host + "/request",
            headers: {"Content-Type":"application/json"},
            params: {id: "1", pwd: "val1"}
        },function (message) {
            var str = JSON.stringify(message); //返回字符串

            document.getElementById('message').innerHTML = "http post response:" + str;
        })
    }

    function testQRCodeScan() {

        hkNativeScan.barCode({type:0},function (message) {
            var str = JSON.stringify(message); //返回字符串

            document.getElementById('message').innerHTML = "scan result:" + str;

            console.log(message);
            // console.log()
        })


       //  var bs = new LBXCustomBase();
       //
       //  var _ALPHA = "cdefghijklmnopqrstuvwxyz0123456789+/ABCDEFGHIJKLMNOPQRSTUVWXYZab";
       //
       //  bs.initCustomEncodeChars(_ALPHA,'=');
       //
       //
       //          var bs64 = bs.encode("1234567890");
       // console.log(bs64);
       //
       // var dbs64 = bs.decode(bs64);
       // console.log(dbs64);
    }



    console.log(window.location.host);
    console.log(window.location.href);

</script>
</body>
</html>
